package cn.zhaozhiqi.config;

import cn.zhaozhiqi.properties.RedisIPProperties;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    //RedissonClient客户端，用作分布式锁
    @Bean
    public RedissonClient redissonClient(RedisIPProperties properties){
        Config config = new Config();
        //使用不同的IP地址，我们拼接一下，使用yml配置即可
        String address = "redis://"+properties.getHost()+":"+properties.getPort();
        config.useSingleServer().setAddress(address);
        return Redisson.create(config);
    }
}
